/*==============================================================================
FILE NAME: Figure_C7.do
CREATED: 25 July 2025
==============================================================================*/


/* Set directory if working independently through code
if c(username)=="" { //insert username
	global rootdir "" // insert root path
	global processed_data "$rootdir/processed_data" 
	global figures "$rootdir/output/figures"  // Define global paths for replication package
} 
*/

*** AIR FIGURE ***
// Share of air complaints by incident nature over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_air == 1
gen COUNT = 1
collapse (sum) ODOR DUST SMOKE OUTDOOR_BURNING OTHER_AIR COUNT, by(year)
foreach x in ODOR DUST SMOKE OUTDOOR_BURNING OTHER_AIR {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline ODOR_SHARE DUST_SHARE SMOKE_SHARE OUTDOOR_BURNING_SHARE, lwidth(medthick medthick medthick medthick medthick)  legend(label(1 "Odor") label(2 "Dust") label(3 "Smoke") label(4 "Outdoor Burning") label(5 "Other") size(large) pos(6) col(5) row(2)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C7_Panel_A.pdf", replace


** WATER FIGURE **
// Share of water complaints by incident nature over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_water == 1
gen COUNT = 1
collapse (sum) WASTEWATER WATER_SUPPLY_QUALITY STORMWATER WATER_SUPPLY_SERVICE OTHER_WATER COUNT, by(year)
foreach x in WASTEWATER WATER_SUPPLY_QUALITY STORMWATER WATER_SUPPLY_SERVICE OTHER_WATER {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline WASTEWATER_SHARE WATER_SUPPLY_QUALITY_SHARE STORMWATER_SHARE WATER_SUPPLY_SERVICE_SHARE, lwidth(medthick medthick medthick medthick medthick) legend(label(1 "Wastewater") label(2 "Water Quality") label(3 "Stormwater") label(4 "Water Supply") label(5 "Other") size(large) pos(6) col(5) row(2)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C7_Panel_B.pdf", replace


*** WASTE FIGURE ****
// Share of waste complaints by incident nature over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_waste == 1
gen COUNT = 1
collapse (sum) ODOR MUNICIPAL INDUSTRIAL PST OTHER_WASTE COUNT, by(year)
foreach x in ODOR MUNICIPAL INDUSTRIAL PST OTHER_WASTE {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline MUNICIPAL_SHARE ODOR_SHARE INDUSTRIAL_SHARE PST_SHARE, lwidth(medthick medthick medthick medthick medthick) legend(label(1 "Municipal Waste") label(2 "Odor") label(3 "Industrial Waste") label(4 "Petroleum Storage Tanks") label(5 "Other") size(large) pos(6) col(5) row(2)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C7_Panel_C.pdf", replace